package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.assemble.AreaAssembler;
import com.tarena.lbs.basic.web.service.AreaService;
import com.tarena.lbs.common.basic.converter.AreaConverter;
import com.tarena.lbs.pojo.basic.bo.AreaBO;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class AreaController {
    @Autowired
    private AreaService areaService;
    @Autowired
    private AreaConverter areaConverter;

    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> proviceList() throws BusinessException{
        List<AreaBO> areaBOS = areaService.queryAreaList(0L);
        List<AreaVO> areaVOS = areaConverter.boList2VoList(areaBOS);
        return new Result<>(areaVOS);
    }
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> childrenList(@PathVariable Long parentId) throws BusinessException{
        List<AreaBO> areaBOS = areaService.queryAreaList(parentId);
        List<AreaVO> areaVOS = areaConverter.boList2VoList(areaBOS);
        return new Result<>(areaVOS);
    }

    @Autowired
    private AreaAssembler areaAssembler;
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> areaTree(){
        List<AreaVO> areaVOS = areaAssembler.assembleAreaTree();
        return new Result<>(areaVOS);
    }
}
